import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:lib_uikit/lib_uikit.dart';
import 'package:lottie/lottie.dart';

const _kGTLoadingDialogV3 = 'kGTLoadingDialogV3';

/// Loading浮层
class GTLoadingDialogV3 extends StatelessWidget {
  const GTLoadingDialogV3({super.key});

  @override
  Widget build(BuildContext context) {
    //UnconstrainedBox兼容部分场景直接使用GTLoadingDialogV3 widget
    return UnconstrainedBox(
      child: GestureDetector(
        onTap: () {
          GTLoadingDialogV3.dismiss();
        },
        child: SizedBox(
          width: 92,
          child: Container(
            decoration: BoxDecoration(
                color: GTColorsV3.cmpt1.color,
                borderRadius: BorderRadius.circular(8),
                boxShadow: [
                  BoxShadow(
                      color: GTColorsV3.pop_menu_shadow.color.withOpacity(0.12),
                      blurRadius: 12.0,
                      offset: const Offset(0, 3))
                ]),
            padding: const EdgeInsets.all(28.0),
            child: SizedBox(
              width: 36,
              child: Lottie.asset(
                'packages/lib_uikit/assets/json/gt_loading_lottie.json',
                repeat: true,
                animate: true,
              ),
            ),
          ),
        ),
      ),
    );
  }

  static GTLoadingDialogV3? show({BuildContext? context}) {
    var dialog = const GTLoadingDialogV3();
    SmartDialog.show(
      usePenetrate: false,
      clickMaskDismiss: true,
      animationType: SmartAnimationType.fade,
      maskColor: Colors.transparent,
      tag: _kGTLoadingDialogV3,
      builder: (_) {
        return dialog;
      },
    );

    return dialog;
  }

  static void dismiss({GTLoadingDialogV3? dialog}) {
    SmartDialog.dismiss(tag: _kGTLoadingDialogV3);
  }
}
